Adding Custom Buttons
Q:
How do you add buttons and assign functionality to them? For example, adding a button that removes the curly quotes from Word and replaces them with quot tags?
A:
You may want to have a look at the Telerik documentation concerning this: http://www.telerik.com/help/aspnet/editor/
switch to the “index” tab and look for Adding Buttons.
In your particular case the actions should be as below:
- The buttons for the editor is located here:
/Sitecore/System/Settings/Html Editor Profiles/Rich Text Default/Toolbar X.
Copy an existing button and rename it to whatever you like. In this instance we'll call the button MyPaste. In the Click field you can enter a string that will be fired when the button is clicked. You can catch this message when it is fired. We'll enter "MyPaste".
- We need to catch the message. This is done in the javascript file: sitecore/shell/Controls/Rich Text Editor/RichText Commands.js. Add the following lines to the file:
RadEditorCommandList["MyPaste"] = function(commandName, editor, tool) {
/* Fire InsertSitecoreLink events */
//editor.Fire("InsertSitecoreLink",tool);
var text = editor.GetHtml(true); //get the HTML content
// Replace the "curly quotes" with straight quotation marks
// and leave the contents of the quote (stored in $1) unchanged.
var quote = /`([^`]*)`/g;
text=text.replace(quote, "\"$1\"");
//Clear old HTML
editor.SetHtml("");
//Paste new HTML
editor.SetHtml(text);
};